﻿using Business;
using Business.Solr;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;

namespace Web.Controllers
{
    public class ResumesController : Controller
    {
        private readonly ResumeRepo _ResumeRepo;

        public ResumesController() {
            var solrClient = new SolrClient(Config.GetValue("SolrUpdateUrl"), Config.GetValue("SolrSelectUrl"));
            _ResumeRepo = new ResumeRepo(solrClient);
        }
        
        public ActionResult Index(string q)
        {
            // 从QueryString中找到筛选条件
            var filters = Request.QueryString.AllKeys
                .Where(_ => string.Compare(_, "q", true) != 0)
                .ToDictionary(_ => _, _ => Request.QueryString[_]);

            var response = _ResumeRepo.Query(q, filters);
            return View(response);
        }

        public ActionResult Details(string phoneNumber, string q) {
            var body = _ResumeRepo.GetBodyByPhoneNumber(phoneNumber, q);
            return Content(body);
        }
    }
}
